/*
 * DEMSurface.h
 *
 *  Created on: 24/ago/2012
 *      Author: andrevb
 */


#ifndef MOLEM_DEMSURFACE_H_
#define MOLEM_DEMSURFACE_H_

#include "DEMElement.h"
#include <vector>

namespace MOLEM {

enum SurfStatus {
	VALUES_NOT_SET,
	VALUES_CORRECTLY_SET,
	DEPRESSION_FILLING_PERFORMED,
	GRADIENT_FIELD_INITIALIZED,
	GRADIENT_FIELD_UNINITIALIZED
};

class DEMSurface {
public:
	/**
	 * Initialize a (nr x nc) surface.
	 */
	DEMSurface(unsigned int nr, unsigned int nc);
	~DEMSurface();

	/**
	 * Set values contained in given parameter as z values of this surface,
	 * row by row. Parameter therefore should be of length nrxnc.
	 */
	SurfStatus setValues(std::vector<double>&);
	/**
	 * Evaluates the sum of z-values
	 */
	double getSumZvalues();
	/*
	 * Check if values has been set then performs depression filling
	 * and initialize the gradient field
	 */
	SurfStatus initGradientField();
	//MolemStatus initLinks();
	//MolemStatus initBasins();

	//Basin& getLargestBasin();

private:
	SurfStatus state;
	static const double SUM_Z_DEFAULT_VALUE = -12.0;
	const unsigned int nr;
	const unsigned int nc;
	std::vector<DEMElement* > datas;
	double sumZvalues;

	void initElements();
	void connectElements();

	/**
	 * Perform depression filling on the DEM
	 */
	SurfStatus depressionFilling();
};

} /* namespace MOLEM */
#endif  /* MOLEM_DEMSURFACE_H_ */
